home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / extras / Direct3D / Tools / Maya30 / bicubicbezierpatches.mel next >
Encoding:
Text File  |  2001-10-08  |  4.8 KB  |  173 lines

  1. // PLEASE NOTE: This file is a modified version of bezierPatches.mel
  2. //
  3. // bicubicBezierPatches()
  4. //
  5. //
  6. // To run: Select surfaces.  Type bicubicBezierPatches();
  7. //
  8. // Get Bezier patch Bezier mesh forced to cubic.
  9. //
  10. // To make things cleaner, construction history and "keep originals"
  11. // options are forced to false.  If you search for "BEHAVIOUR" in this
  12. // file, you can edit a couple of variables in that section and change
  13. // this.
  14.  
  15. proc rebuildIntoCubics( int $v2 )
  16. {
  17.     // Save the values that we're changing:
  18.     int $oldType = `optionVar -q rebuildSurfaceType`;
  19.     int $degU = `optionVar -q rebuildSurfaceTypUniformDegreeU`;
  20.     int $degV = `optionVar -q rebuildSurfaceTypUniformDegreeV`;
  21.     int $kcv = `optionVar -q rebuildSurfaceKeepControlPoints`;
  22.  
  23.     // Force uniform rebuild into bi-quadratic, same # cvs:
  24.     optionVar -iv rebuildSurfaceType 0;
  25.     optionVar -iv rebuildSurfaceTypUniformDegreeU 3;
  26.     optionVar -iv rebuildSurfaceTypUniformDegreeV 3;
  27.     optionVar -iv rebuildSurfaceKeepControlPoints 1;
  28.  
  29.     string $cmd;
  30.     if( $v2 ) {
  31.         $cmd = "performRebuildSurface( 0 )";
  32.     }
  33.     else {
  34.         $cmd = "rebuildSurfaceToolScript( 0 )";
  35.     }
  36.     eval($cmd);
  37.  
  38.     // Restore the values we changed:
  39.     optionVar -iv rebuildSurfaceType $oldType;
  40.     optionVar -iv rebuildSurfaceTypUniformDegreeU $degU;
  41.     optionVar -iv rebuildSurfaceTypUniformDegreeV $degV;
  42.     optionVar -iv rebuildSurfaceKeepControlPoints $kcv;
  43. }
  44.  
  45. proc extractbPatches( int $v2, int $dir, int $mesh )
  46. {
  47.     global int $gSelectNurbsSurfacesBit;
  48.  
  49.     string $surfaces[] = `filterExpand -ex true -sm $gSelectNurbsSurfacesBit`;
  50.     string $tmpSurf[];
  51.     string $isos[];
  52.     string $cmd;
  53.     int $openIt;
  54.  
  55.     int $i, $n = size($surfaces);
  56.     if( $n > 0 ) {
  57.  
  58.         // If some are periodic, make them open first:
  59.         for( $i=0; $i<$n; $i+=1 ) {
  60.             $tmpSurf[0] = $surfaces[$i];
  61.             $openIt = false;
  62.             if( 0 == $dir ) {
  63.                 if( 2 == `getAttr ($tmpSurf[0] + ".fu")` ) {
  64.                     $openIt = true;
  65.                 }
  66.             }
  67.             else {
  68.                 if( 2 == `getAttr ($tmpSurf[0] + ".fv")` ) {
  69.                     $openIt = true;
  70.                 }
  71.             }
  72.  
  73.             if( $openIt ) {
  74.                 selectVisibleIsoparms( $tmpSurf, $isos, 0, $dir, true );
  75.                 if( size($isos) > 0 ) {
  76.                     select -r $isos[0];
  77.                     if( $v2 ) {
  78.                         $cmd = "performDetach( 0, \"Surface\" )";
  79.                     }
  80.                     else {
  81.                         $cmd = "detachSurfaceToolScript( 0 )";
  82.                     }
  83.                     eval( $cmd );
  84.                 }
  85.             }
  86.         }
  87.  
  88.         int $ignoredTrims = selectVisibleIsoparms( $surfaces, $isos,
  89.                                                    0, $dir, false );
  90.  
  91.         if( $ignoredTrims > 0 ) {
  92.             warning( "Ignored trim information of " +
  93.                      $ignoredTrims + " surfaces." );
  94.         }
  95.  
  96.         $cmd = "select -r ";
  97.         $n = size($isos);
  98.         for( $i=0; $i<$n; $i+=1 ) {
  99.             $cmd += $isos[$i] + " ";
  100.         }
  101.         eval($cmd);
  102.  
  103.         if( $mesh ) {
  104.             if( $v2 ) {
  105.                 $cmd = "performInsertKnot( 0, \"Surface\" )";
  106.             }
  107.             else {
  108.                 $cmd = "insertSurfaceToolScript( 0 )";
  109.             }
  110.         }
  111.         else {
  112.             if( $v2 ) {
  113.                 $cmd = "performDetach( 0, \"Surface\" )";
  114.             }
  115.             else {
  116.                 $cmd = "detachSurfaceToolScript( 0 )";
  117.             }
  118.         }
  119.         eval($cmd);
  120.         deleteInvalidNurbs 1;
  121.     }
  122. }
  123.  
  124. global proc bicubicBezierPatches()
  125. {
  126.     // BEHAVIOUR:
  127.     // You can change the value here if you want a different behaviour.
  128.     int $forceConstructionHistoryTo = false;
  129.     int $forceKeepOriginalsTo = false;
  130.  
  131.     // Remember the original values for history and keep originals:
  132.     int $origConstructionHistory = `constructionHistory -q -tgl`;
  133.     int $origKeepOriginalsRebuild = `optionVar -q rebuildSurfaceKeepOriginal`;
  134.     int $origKeepOriginalsDetach = `optionVar -q detachKeepOriginal`;
  135.     int $origKeepOriginalsInsert = `optionVar -q insertKnotKeepOriginal`;
  136.     int $origInsertKnotNumber = `optionVar -q insertKnotNumberOfKnotsToInsert`;
  137.     int $origInsertKnotAdd = `optionVar -q insertKnotAddOrComplement`;
  138.     int $origInsertBetween = `optionVar -q insertKnotBetween`;
  139.  
  140.  
  141.     // Force the new values:
  142.     constructionHistory -tgl $forceConstructionHistoryTo;
  143.     optionVar -iv rebuildSurfaceKeepOriginal $forceKeepOriginalsTo;
  144.     optionVar -iv detachKeepOriginal $forceKeepOriginalsTo;
  145.     optionVar -iv insertKnotKeepOriginal $forceKeepOriginalsTo;
  146.     optionVar -iv insertKnotAddOrComplement 0;
  147.     optionVar -iv insertKnotBetween 0;
  148.     optionVar -iv insertKnotNumberOfKnotsToInsert 3;
  149.  
  150.     int $v2 = false;
  151.     string $v = `about -v`;
  152.     if( "2.0" == $v ) {
  153.         $v2 = true;
  154.     }
  155.  
  156.     rebuildIntoCubics( $v2 );
  157.  
  158.     extractbPatches( $v2, 0, 1 );
  159.     extractbPatches( $v2, 1, 1 );
  160.  
  161.     ls -sl;
  162.  
  163.     // Reset the original values:
  164.     constructionHistory -tgl $origConstructionHistory;
  165.     optionVar -iv rebuildSurfaceKeepOriginal $origKeepOriginalsRebuild;
  166.     optionVar -iv detachKeepOriginal $origKeepOriginalsDetach;
  167.     optionVar -iv insertKnotKeepOriginal $origKeepOriginalsInsert;
  168.     optionVar -iv insertKnotNumberOfKnotsToInsert $origInsertKnotNumber;
  169.     optionVar -iv insertKnotAddOrComplement $origInsertKnotAdd;
  170.     optionVar -iv insertKnotBetween $origInsertBetween;
  171. }
  172.  
  173.